package com.vcs.frm.web;

import java.security.Principal;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.vcs.frm.domain.NoticeBoard;
import com.vcs.frm.service.CommonService;

@Controller
public class HomeController {

	Log log = LogFactory.getLog(this.getClass());

	@Autowired
	private CommonService commonService;

	public void setCommonService(CommonService commonService) {
		this.commonService = commonService;
	}

	@RequestMapping( { "/", "/home", "/notice" })
	public ModelAndView welcomeHandler(Model model, Principal principal,
			HttpSession session) {
		log.info("---------- welcomeHandler ");
		ModelAndView mav = new ModelAndView();
		// 1 Fetch home page notice board and thought of the day data.
		NoticeBoard noticeBoard = commonService.getNoticeBoard();

		// 2. Fetch data for thought of the day

		mav.addObject("noticeBoard", noticeBoard);
		mav.setViewName("home");
		return mav;
	}

	@RequestMapping("/bachpan-crm")
	public String defaultHandler(Model model) {
		log.info("---------- defaultHandler ");
		return "home";
	}

	@RequestMapping("/sessionExpired")
	public String sessionExpiredHandler(Model model) {
		log.info("---------- defaultHandler ");
		return "sessionExpired";
	}
}
